new Handle:g_Items = INVALID_HANDLE
new Handle:g_RemoveSave = INVALID_HANDLE

//---------------------------------------//
// Here we let items and weapons respawn //
//---------------------------------------//
public ItemRespawn(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (Synergy && StringToInt(newValue) == 1)
	{
		new index = -1
		while ((index = FindEntityByClassname2(index, "weapon_*")) != -1)
			DispatchKeyValue(index, "RespawnCount", "-1")
		while ((index = FindEntityByClassname2(index, "item_*")) != -1)
			DispatchKeyValue(index, "RespawnCount", "-1")
		PrintToServer("[SYN] Items Respawn Enabled")
	}
	else
	{
		PrintToServer("[SYN] Items Respawn Disabled")
	}
}

//--------------------------------------------------------//
// We create a Timer to make sure map got complete loaded //
//--------------------------------------------------------//
public DO_SaveKill(Handle:convar, const String:oldValue[], const String:newValue[])
{
	if (Synergy && StringToInt(newValue) == 1)
	{
		CreateTimer(2.0, SaveKill)
	}
}

//--------------------------------------------------------------//
// Here we remove all the Autosave related triggers and entites //
//--------------------------------------------------------------//
public Action:SaveKill(Handle:timer)
{
	decl String:name[32]
	new index = -1

	for (new i=0; i < GetMaxEntities(); i++)
	{
		if (IsValidEntity(i))
		{
			if (GetEdictClassname(i, name, sizeof(name)))
			{
				if (StrContains(name, "trigger_autosave", false) != -1)
				{
					RemoveEdict(i)
					if (Debug)
						PrintToServer("[SYN] Found trigger_autosave")
				}
			}
		}
	}

	while ((index = FindEntityByClassname2(index, "logic_autosave")) != -1){
		AcceptEntityInput(index, "kill")
		if (Debug)
			PrintToServer("[SYN] Found logic_autosave")
	}
		
	while ((index = FindEntityByClassname2(index, "logic_active_autosave")) != -1){
		AcceptEntityInput(index, "kill")
		if (Debug)
			PrintToServer("[SYN] Found logic_active_autosave")
	}

	SetConVarInt(FindConVar("save_disable"), 1)
	SetConVarInt(FindConVar("save_history_count"), 0)
	SetConVarInt(FindConVar("sv_autosave"), 0)

	PrintToServer("[SYN] Removed all relevant autosave triggers")
}